<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
//确认债权
function doAddCredit(obj){
	var table=iframeCredit.iframeObj["table"];
	var transferIds = table.getSelectedObjs("transferId");
	transferIds = "" + transferIds;
	var thisMakeCreditorValues = table.getSelectedObjs("thisMakeCreditorValue");
	thisMakeCreditorValues = "" + thisMakeCreditorValues;
	var valueContractCode = $('#dtocontractCode').val();
	var valueAgreementCode = $('#dtoagreementCode').val();
	var cooperorgCode = $('#dtocooperorgCode').val();
	var ids = table.getSelectedObjs("id");
	var dealType = $('#creditorAffirmRule').val();
	var billDate = $('#statementDate').val();
	var packageNum = $('#creditPackage').val();
	ids = "" + ids;
	var dealCode = $('#dealCode').val();
	var id = $('#idValue').val();
	var dataUrl =contextRootPath + "/cooperorgDeal/updateQuotaDetailBySecondBuy";	
	$.ajax({
		url: dataUrl,
		type: 'post',
		dataType: 'json',
		data:{"transferIds":transferIds,
			"thisMakeCreditorValues":thisMakeCreditorValues,
			"ids":ids,
			"dealCode":dealCode,
			"contractCode":valueContractCode,
			"argeementCode":valueAgreementCode,
			"cooperorgCode":cooperorgCode,
			"id":id,
			"settleDealCodes":"${dealCodes}",
			"billDate":billDate,
			"packageNum":packageNum,
			"dealType":cimsConstant.DEAL_TYPE_SECOND_PURCHASE},
		error: function(result) {
			alert("请查看返回数据是否正确：" + result);
		},
		success: function(results) {
			var obj = results.data;
			$("#idValue").val(obj.id);
			$("#dealCode").val(obj.dealCode);
			initFnCreditDetailView(transferIds);
			$("#creditDetailTable").show();
			CreditValueSum();
			$("#isDeleteAndIsExport").val("true");
			
		}
	});
	
	
	
}
function saveCreditDeal(){
	var valueCooperorgCode = $('#dtocooperorgCode').val();
	var valueContractCode = $('#dtocontractCode').val();
	var valueQuotaSum = $('#dtoquotaSum').val();
	var creditPackageName = $('#creditPackageWrite').val();
	var dealCode = $('#dealCode').val();
	var id = $('#idValue').val();
	var sumCreditorValue = $('#sumCreditorValue').val();
	var detialNumber = $('#detialNumber').val();
	var creditorAffirmRule = $('#creditorAffirmRule').val();
	var dtoagreementCode = $('#dtoagreementCode').val();
	var billDate = $('#statementDate').val();
	if(null==creditorAffirmRule||""==creditorAffirmRule){
		alert("请选择交易类型！");
		return;
	}
	if(null==valueCooperorgCode||""==valueCooperorgCode){
		alert("请选择合约！");
		return;
	}
	
	/* if(null==dealCode||""==dealCode){
		alert("请选择债权！");
		return;
	} */
	
	if(confirm("确认保存！")){
		var dataUrl =contextRootPath + "/cooperorgDeal/saveCooperorgDeal";
		$.ajax({
			url: dataUrl,
			type: 'post',
			dataType: 'json',
			data:{"cooperorgCode":valueCooperorgCode,
				  "contractCode":valueContractCode,
				  "planSellSum":valueQuotaSum,
				  "creditPackageName":creditPackageName,
				  "billDate":billDate,
				  "dealCode":dealCode,
				  "dealCodes":"${dealCodes}",
				  "id":id,
				  "sumCreditorValue":sumCreditorValue,
				  "detialNumber":detialNumber,
				  "dealType":cimsConstant.DEAL_TYPE_SECOND_PURCHASE,
				  "agreementCode":dtoagreementCode},
			error: function(result) {
				alert("请查看返回数据是否正确：" + result);
			},
			success: function(results) {
				$("#isDeleteAndIsExport").val("true");
				var winObj = parent.tabs.getTabWinByTitle("二次购买");
				winObj.location.reload();
				alert("二次购买成功");
			}
		});
	}
}